/*
 * Copyright (C) 2012 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.ui.components;

import rpg.RPG;
import rpg.gfx.Bitmap;
import rpg.gfx.HSVGradientColor;

/**
 *
 * @author rothens
 */
public class ComponentGradientButton extends ComponentButton {
    private Bitmap[] backgrounds;

    
    

    public ComponentGradientButton(int width, int height, Integer x, Integer y, HSVGradientColor gradient_inactive, HSVGradientColor gradient_active, HSVGradientColor gradient_hover, String text, int[] colors, byte type) {
        super(width, height, x, y);
        backgrounds = new Bitmap[3];
        backgrounds[0] = new Bitmap(width, height);
        backgrounds[1] = new Bitmap(width, height);
        backgrounds[2] = new Bitmap(width, height);
        
        
        
        backgrounds[0] = gradient_inactive.createGradient(backgrounds[0]);        
        backgrounds[1] = StaticTextures.border_active.overlay(gradient_active.createGradient(backgrounds[1]));        
        backgrounds[2] = StaticTextures.border_active.overlay(gradient_hover.createGradient(backgrounds[2]));
        for(int i = 0; i < 3; i++){
            Bitmap b = RPG.fs.getText(text, type, colors[i%colors.length]);
            backgrounds[i].drawOn(b, width/2 - b.width/2, height/2-b.height/2);
        }
        redraw();

    }
    
    public ComponentGradientButton(int width, int height, Integer x, Integer y, HSVGradientColor[] gradients, String text, int[] colors, byte type){
        this(width, height, x, y, gradients[0], gradients[1], gradients[2], text, colors, type);
    }
    
    

    @Override
    public void redraw() {
        clear();
        switch(state){
            case SELECTED:
                draw(backgrounds[0],0,0);
                draw(StaticTextures.border_active.overlay(this),0,0);
                break;
            case INACTIVE:
                draw(backgrounds[0],0,0);
                draw(StaticTextures.border_inactive.overlay(this),0,0);
                break;
            case HOVER:
                draw(backgrounds[0],0,0);
                draw(StaticTextures.border_hover.overlay(this),0,0);
                break;
        }
        if(parent != null){
            ((Component)parent).redraw();
        }
    }
    
}
